﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SuperX.Common.Helper
{
    /// <summary>
    /// 校验帮助类
    /// </summary>
    public class CheckUtil
    {
        /// <summary>
        /// 空字符串判断
        /// </summary>
        /// <param name="param"></param>
        /// <param name="paramName"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>        
        public static string NotNullOrWhiteSpace(string param, string paramName)
        {
            if (string.IsNullOrWhiteSpace(param))
            {
                throw new ArgumentException(paramName + " is null or white Space", paramName);
            }
            return param;
        }

        /// <summary>
        /// 空字符串判断
        /// </summary>
        /// <param name="param"></param>
        /// <param name="paramName"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public static string NotNullOrEmpty(string param, string paramName)
        {
            if (string.IsNullOrEmpty(param))
            {
                throw new ArgumentException(paramName + " is null or empty", paramName);
            }
            return param;
        }

        /// <summary>
        /// 空字符串判断
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="param"></param>
        /// <param name="paramName"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static T NotNull<T>(T param, string paramName)
        {
            if (param == null)
            {
                throw new ArgumentNullException(paramName);
            }
            return param;
        }

        /// <summary>
        /// 空字符串判断
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="param"></param>
        /// <param name="paramName"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public static ICollection<T> NotNullOrEmpty<T>(ICollection<T> param, string paramName)
        {
            if (param == null || param.Count <= 0)
            {
                throw new ArgumentException(paramName + " is null or empty", paramName);
            }
            return param;
        }
    }
}
